package com.lwj.liwanjia.model;

import com.lwj.liwanjia.api.ApiService;
import com.lwj.liwanjia.bean.UrlBean;
import com.lwj.liwanjia.bean.fabu.FabuBbBean;
import com.lwj.liwanjia.utils.RetrofitHelper;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/1/14.
 */

public class FabuBbModel {
    public void uploadBb(List<File> files, String token, Subscriber<FabuBbBean> subscriber) {
        Map<String, RequestBody> maps = new HashMap<>();
        if (files != null && files.size() > 0) {
            for (int i = 0; i < files.size(); i++) {
                RequestBody body =
                        RequestBody.create(MediaType.parse("application/otcet-stream"), files.get(i));
                maps.put("AttachmentKey" + i + "\"; filename=\"" + files.get(i).getName(), body);
            }
            RetrofitHelper.getSingleRetrofit().create(ApiService.class)
                    .uploadBb(maps,token)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(subscriber);
        }
    }
}
